package org.example.game.history;

import java.util.HashMap;

/**
 * @Description: TODO
 * @Author wyatt
 * @Data 2024/07/06 23:29
 */
public class Solution100338 {

    public static void main(String[] args) {
        System.out.println(new Solution100338().countSubarrays(new int[]{1,2,3}, 2));
    }

    public long countSubarrays(int[] nums, int k) {
        long sum = 0;
        HashMap<Integer, Integer> numMap = new HashMap<>();
        for (int num : nums) {
            numMap.putIfAbsent(num , 0);
            numMap.put(num, numMap.get(num) + 1);
        }

        for (Integer keyA : numMap.keySet()) {
            for(Integer keyB : numMap.keySet()){
                if((keyA & keyB) == k){
                    sum += numMap.get(keyA);
                    sum += numMap.get(keyB);
                }
            }
        }
        sum = sum/2;
        return sum*(sum+1)/2;

    }

}
